package com.hsq.ndmall.wx.controller;

import com.hsq.ndmall.common.utils.R;
import com.hsq.ndmall.wx.common.StorageProperties;
import com.hsq.ndmall.wx.service.StorageService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.Map;

/**
 * @author 黄四清
 * @version 1.0.0
 * @ClassName StorageController.java
 * @Description TODO  对象存储服务
 * @createTime 2021年08月25日 19:21:00
 */
@RestController
@RequestMapping("wx/storage")
public class StorageController {

    @Autowired
    private StorageService storageService;

    @PostMapping("upload")
    public R putFile(@RequestParam("file") MultipartFile file) {
        if (file == null) {
            System.out.println("文件为空~~~~~~~~~~~~~~");
            return R.error("文件为空");
        }
        Map map = storageService.putFile(file);
        return R.ok(map);
    }

    @GetMapping("download")
    public R getFile(@RequestParam String key) {
        Map file = storageService.getFile(key);
        return R.ok(file);
    }

}
